<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <b class="u-f-16">
          <span>添加代理商收益记录</span>
        </b>
        <div class="u-right u-5mt">
          <el-button
            type="success"
            size="small"
            icon="el-icon-document-checked"
            @click="submitCheck('objForm')"
            v-if="hasPerm('agencyExtractEditPost')"
            >提交保存</el-button
          >
          <el-button size="small" icon="el-icon-back" @click="$router.go(-1)"
            >返回</el-button
          >
        </div>
      </div>
      <el-form
        :model="objForm"
        :rules="rules"
        ref="objForm"
        label-width="100px"
        class="u-form"
      >
        <el-form-item label="选择代理商">
          <el-input
            v-model="objForm.agency_id"
            placeholder="代理商id"
            type="hidden"
            style="display: none"
          ></el-input>
          <el-input
            v-model="agency_name"
            placeholder="名称"
            disabled
            v-if="objForm.agency_id > 0"
          ></el-input>
          <el-button type="text" @click="is_user_show = true"
            >选择代理商</el-button
          >
        </el-form-item>
        <el-form-item label="提现金额">
          <el-input v-model="objForm.price" placeholder="提现金额"></el-input>
        </el-form-item>
      </el-form>
      <!-- 用户弹出框 -->
      <el-dialog title="选择代理商" :visible.sync="is_user_show" width="60%">
        <Agency :isprops="true" @user_select="user_select"></Agency>

        <span slot="footer" class="dialog-footer">
          <el-button @click="is_user_show = false">取 消</el-button>
          <el-button type="primary" @click="is_user_show = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import commonEdit from "@/mixins/common-edit";
import Agency from "@/views/agency/agency.vue";

export default {
  components: {
    Agency,
  },
  mixins: [commonEdit],

  data() {
    return {
      apiName: "agency",
      backRoute: "agencyExtractIndex", //成功跳转地址
      is_user_show: false,
      objForm: {
        agency_id: "", //代理商id
        price: "", //金额
      },
      agency_name:"",
    };
  },
  methods: {
    user_select(item){
      this.is_user_show = false;
      this.objForm.agency_id = item.id;
      this.agency_name = item.agency_title+"（账号："+item.agency_login_username+"）";

    },
    submitCheck() {
      const self = this;
      self.$api[self.apiName]
        .agencyExtractSave(self.objForm)
        .then((response) => {
          if (response.code == 1) {
            self.$message({
              message: "操作成功",
              type: "success",
            });
            self.$router
              .push({
                name: self.backRoute,
                params: { page: self.currentPage, id: self.backPid },
              })
              .catch(() => {});
          }
        });
    },
  },
  created() {},
};
</script>
